package page.pc.riskEducationPage;

import basicTool.WaitTool;
import com.customize.reporter.WebReporter;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.ui.ExpectedConditions;
import page.pc.AbstractPCPage;

import java.util.List;
import java.util.Random;

/**
 * Created by lomo on 2017.
 */
public class RiskEducationPage extends AbstractPCPage{

    @FindBy(css = ".common-wrap.cat-banner.n-banner>.banner-text")
    private WebElement riskEducationBannerArea;

    @FindBy(css = ".cat-wrap .new-pcNews>li")
    private List<WebElement> riskEducationNewsList;

    @FindBy(css = ".hot-artical.pull-right.page-hot .hot-list>li")
    private List<WebElement> riskEducationHotNewsList;



    public RiskEducationPage(WebDriver driver){
        super(driver);
        WaitTool.waitFor(driver, ExpectedConditions.visibilityOf(riskEducationBannerArea), 60);
    }

    public RiskEducationNewsDetailPage clickRiskNewsLinkRandomly() throws Exception {
        WebReporter.log(driver, driver.getTitle(), true, true);
        JavascriptExecutor jse = (JavascriptExecutor) driver;
        int n = new Random().nextInt(riskEducationNewsList.size());
        System.out.println("点击风险教育NewsList中的第：" + n + " 条新闻Link");
        jse.executeScript("document.getElementsByClassName('news-title')[" + n + "].click()");
        return new RiskEducationNewsDetailPage(driver);
    }

    public RiskEducationNewsDetailPage clickRiskEducationHotNewsRandomly() throws Exception {
        return click(riskEducationHotNewsList.get(new Random().nextInt(riskEducationHotNewsList.size())), RiskEducationNewsDetailPage.class);
    }

}
